package m2_work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
        public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");

        Channel c = f.newConnection().createChannel();
        //b:是否为持久队列  b1:是否排他队列(独占队列)  b2:没有消费者是否自动删除  b3:其他属性设置
        c.queueDeclare("helloworld",true,false,false,null);

        while (true){
            System.out.println("请输入消息");
            String msg = new Scanner(System.in).nextLine();
            //第三个参数标识消息持久化
            c.basicPublish("","helloworld", MessageProperties.PERSISTENT_TEXT_PLAIN,msg.getBytes());
            System.out.println("ok");
        }
    }
}
